package cn.anlab.anappframe.demo.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.anlab.anappframe.R;
import cn.anlab.anappframe.activity.PhotoActivity;
import cn.anlab.anappframe.anim.ActivitySwitcher;
import cn.anlab.anappframe.demo.DemoDataUtil;
import cn.anlab.anappframe.demo.adapter.HomeAdapter;
import cn.anlab.anappframe.service.CoreService;
import cn.anlab.anappframe.system.CoreApplication;

import com.gallery.ActivityMain;

public class HomeDemoActivity extends Activity {
	
	ImageView banner;
	ImageView bannerx;
	TextView tv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_home);
		GridView gv = (GridView)findViewById(R.id.home_menu_gridview);
		gv.setVerticalSpacing(20);
		gv.setSelector(new ColorDrawable(Color.TRANSPARENT));
		HomeAdapter adapter = new HomeAdapter(this, DemoDataUtil.getHomeItem(10));
		gv.setAdapter(adapter);
		
		gv.setOnItemClickListener(menuClickListener);

		banner = (ImageView)findViewById(R.id.imageView1);
		banner.setVisibility(View.GONE);
		bannerx = (ImageView)findViewById(R.id.imageView2);
		tv = (TextView)findViewById(R.id.textView1);
		tv.setText(getResources().getString(R.string.app_name));
		
	}
	
	@Override
	protected void onResume() {
		// animateIn this activity
		ActivitySwitcher.animationIn(findViewById(R.id.container), getWindowManager());
		super.onResume();
	}

		@Override
		public void finish() {
			// we need to override this to performe the animtationOut on each
			// finish.
			ActivitySwitcher.animationOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				@Override
				public void onAnimationFinished() {
					HomeDemoActivity.super.finish();
					// disable default animation
					overridePendingTransition(0, 0);
				}
			});
		}
	// ...
	
	
	private AdapterView.OnItemClickListener menuClickListener = new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			switch (position) {
			case 0:
				startActivity(new Intent(HomeDemoActivity.this, WidgetDemoActivity.class));
				break;
			case 1:
				startActivity(new Intent(HomeDemoActivity.this, ChatDemoActivity.class));
				break;
			case 2:			//开启服务
//				Toast.makeText(HomeDemoActivity.this, "start service ...", Toast.LENGTH_SHORT).show();
//				startService(new Intent(HomeDemoActivity.this, CoreService.class));
				startActivity(new Intent(HomeDemoActivity.this, PullToRefreshListViewDemoActivity.class));
				break;
			case 3:
//				startActivity(new Intent(HomeDemoActivity.this, ListViewDemoActivity.class));
				// we only animateOut this activity here.
				// The new activity will animateIn from its onResume() - be sure to implement it.
				final Intent intent = new Intent(getApplicationContext(), ListViewDemoActivity.class);
				// disable default animation for new intent
				intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
				ActivitySwitcher.animationOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
					@Override
					public void onAnimationFinished() {
						startActivity(intent);
					}
				});
				break;				
			case 4:
				//国际化
				CoreApplication.changeChannel("ca");
				 tv.setText(getResources().getString(R.string.app_name));
				 bannerx.setImageDrawable(getResources().getDrawable(R.drawable.app_bannerx));
				break;
			case 5:
				//国际化
				CoreApplication.changeChannel("cb");
				 tv.setText(getResources().getString(R.string.app_name));
				 bannerx.setImageDrawable(getResources().getDrawable(R.drawable.app_bannerx));
				break;
			case 6:
				//国际化
				CoreApplication.changeChannel("cc");
				 tv.setText(getResources().getString(R.string.app_name));
				 bannerx.setImageDrawable(getResources().getDrawable(R.drawable.app_bannerx));
				break;				
			case 7:
				banner.setImageLevel(0);
//				startActivity(new Intent(HomeDemoActivity.this, DimensActivity.class));
				startActivity(new Intent(HomeDemoActivity.this, ActivityMain.class));
				break;
			case 8:
				banner.setImageLevel(1);
				startActivity(new Intent(HomeDemoActivity.this, ActivityGroupDemoActivity.class));
				break;
			case 9:
				banner.setImageLevel(2);
				startActivity(new Intent(HomeDemoActivity.this, PhotoActivity.class));
				break;

			default:
				break;
			}
		}
	};

}
